﻿@using RoccaStore.Web.Helpers
@using RoccaStore.Extensions
@model RoccaStore.Web.Models.FileViewModel
@{
    ViewBag.Title = "Successfuly stored " + Model.Slug.Title;
    Layout = "~/Views/Shared/_Layout.cshtml";
    int minchars = 0;
    int zindex = 9999;

    if (Html.Account() == null)
    {
        minchars = 100;
        zindex = 0;
    }
}
<div class="content">
    <a href="/" class="logo  middle"></a>
    <h1><b>Congratulations!</b> Your upload completed successfully</h1>
    <div class="box">
        @if (Html.Account() != null)
        {
            <a href="javascript:;" class="share-facebook">Share on Facebook</a>
        }
        <div class="download-link">
            <a href="http://@Request.Url.Authority/@Model.Slug.Name/@(Model.Slug.IsSecure ? Model.Slug.Key : string.Empty)">@Model.Slug.Title<span>@Model.FormattedSize</span></a>
        </div>
        <a href="javascript:;" class="send-email">Email this link</a>
        <a href="@Url.Action("Secure", "File", new { slug = Model.Slug.Name, hash = Model.Slug.Key })" class="secure-link">Secure this link</a>
        <!-- /download-link -->
        <p class="clear">Share link</p>
        <input type="text" value="http://@Request.Url.Authority/@Model.Slug.Name/@(Model.Slug.IsSecure ? Model.Slug.Key : string.Empty)" readonly="readonly" class="share-link txt-download" />
        <div>
            <p>Delete link</p>
            <input type="text" value="http://@Request.Url.Authority/delete/@Model.Slug.Name/@Model.Slug.Key"
                readonly="readonly" class="share-link txt-delete" />
        </div>
        <!-- /nodisplay -->
    </div>
    <!-- /box -->
    <div class="nodisplay">
        <div class="box send-email-box">
            <p class="msg-good">Enter a recipient</p>
            @using (Html.BeginForm("SendDownload", "Email", new { }, FormMethod.Post, new { @class = "validate-form" }))
            {
                <input type="hidden" name="slugName" value="@Model.Slug.Name" />
                <input type="text" name="from" class="required email" placeholder="From e-mail address" value="@(Model.Account != null ? Model.Account.Email : string.Empty)" />
                <input type="text" id="to" name="to" class="required" placeholder="To e-mail address" />
                <div class="clear">
                    <div class="download-notify left">
                        <input type="checkbox" name="notify" value="true" checked="checked" />
                        <label>notification e-mail when file downloaded?</label>
                    </div>
                    <input type="submit" id="btn-send" name="send-button" value="Send" class="right" />
                </div>
            }
        </div>
        <!-- /box-tip -->
    </div>
    <!-- /nodisplay -->
</div>
<!-- /content -->
<script type="text/javascript">
    $().ready(function () {
        $("#to").tokenInput("/addressbook/search/", {              
            zindex: @(zindex),
            minChars: @(minchars),
            tokenValue: 'name',
            allowFreeTagging: true,
            tokenDelimiter: ",",
            onAdd: function (token) {
                if (!isValidEmailAddress(token.name)) {
                    $(this).tokenInput("remove", { name: token.name });
                }
            },
            resultsFormatter: function (item) {
                return "<li>" + item.name + "</li>"
            }
        });

        $('.share-facebook').click(function(){
            $.post('/file/sharedownload', { slug: '@(Model.Slug.Name)' }, function() {                
                $.blockUI({
                    message: "File shared successfully", css: { width: '200px', padding: '20px' }, onBlock: function () {                
                        $('.blockOverlay').attr('title', 'Click to unblock').click($.unblockUI);                
                    }
                });
                $(".blockUI.blockMsg").center();
            });
        });
    });
</script>
